package tech.edwardvan.clouda.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import tech.edwardvan.cloudapia.client.CloudAClient;
import tech.edwardvan.cloudapib.client.CloudBClient;
import tech.edwardvan.cloudapib.entity.Message;
import tech.edwardvan.cloudcommon.entity.ServerResponse;

/**
 * 业务A Controller
 *
 * @author EdwardVan
 */
@RestController
@Slf4j
public class CloudAController implements CloudAClient {

    @Autowired
    private CloudBClient cloudBClient;

    @Override
    public ServerResponse<String> send(String messageContent) {
        Message message = new Message();
        message.setContent(messageContent);
        ServerResponse<Message> receive = cloudBClient.receive(message);
        String cloudBReceipt = "";
        if (receive.isSuccess()) {
            cloudBReceipt = receive.getData().getReceipt();
            log.info("cloud-a收到回执:{}", cloudBReceipt);
        } else {
            cloudBReceipt = receive.getMessage();
            log.error("cloud-a收到回执:{}", cloudBReceipt);
        }
        return ServerResponse.successMessage("cloud-a发送信息完成,收到回执:" + cloudBReceipt);
    }
}
